﻿using B.S.DataBase.SuYuan.Domains.Entites;
using B.S.DataBase.SuYuan.ErrorCode;
using B.S.DataBase.SuYuan.Infrastructure.Interfaces;
using B.S.DataBase.SuYuan.Write.API.Applications.Commands.ShopInfo;
using MediatR;

namespace B.S.DataBase.SuYuan.Write.API.Applications.CommandHandlers.ShopInfo
{
    public class ShopDelCommandHandler : IRequestHandler<ShopDelCommand, APIResult<object>>
    {
        private readonly IBaseRepository<ShopInfoModel> sRepo;

        public ShopDelCommandHandler(IBaseRepository<ShopInfoModel> sRepo)
        {
            this.sRepo = sRepo;
        }

        public async Task<APIResult<object>> Handle(ShopDelCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            var obj = request.ShopId.Select(x => new ShopInfoModel { ShopId = x }).ToList();
            //批量删除
            var res = sRepo.DeleteRemove(obj).Result;
            if (res > 0)
            {
                result.Code = ResultCode.删除成功;
                result.Msg = ResultCode.删除成功.ToString();
                result.Data = res;
            }
            else
            {
                result.Code = ResultCode.删除失败;
                result.Msg = ResultCode.删除失败.ToString();
            }
            return await Task.FromResult(result);
        }


    }
}
